package com.example.douyin.music;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.douyin.R;

import java.util.List;
public class MusicAdapter extends BaseAdapter {
    Context context;
    List<MusicBean>list;
    public MusicAdapter(Context context, List<MusicBean> list) {
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() { return list.size(); }
    @Override
    public Object getItem(int position) { return list.get(position); }
    @Override
    public long getItemId(int position) { return position; }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VH vh = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_local,null);
            vh = new VH(convertView);
            convertView.setTag(vh);
        }else{
            vh = (VH) convertView.getTag();
        }
        MusicBean musicBean = list.get(position);
        vh.idTv.setText(musicBean.getId());
        vh.titleTv.setText(musicBean.getTitle());
        vh.singerTv.setText(musicBean.getSinger());
        vh.albumTv.setText(musicBean.getAlbum());
        vh.timeTv.setText(musicBean.getDuration());
        return convertView;
    }
    class VH{
        TextView idTv,titleTv,singerTv,albumTv,timeTv;
        public VH(View v){
            idTv = v.findViewById(R.id.item_local_tv_id);
            titleTv = v.findViewById(R.id.item_local_tv_title);
            singerTv = v.findViewById(R.id.item_local_tv_singer);
            albumTv = v.findViewById(R.id.item_local_tv_album);
            timeTv = v.findViewById(R.id.item_local_tv_duration);
        }
    }
}
